<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>{{msg}}</h1>

        <button @click='updateData'>点击更改数据</button>

    </div>
    <script src="./vue.js"></script>
    <script>
        //创建 new  Vue() 系统自动在某个节点帮你执行这些钩子函数

        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'vue',
                list: ['node']
            },
            beforeCreate() {
                console.log('beforeCreate')
                //     console.log(this.$el)
                //     console.log(this.$data)
                //     console.log(this.msg)
                //    console.log('打印list:',this.list)
            },
            created() {  // data数据加载了  
                //     console.log(this.list)
                //     // this.list=res.data 
                //     setTimeout(()=>{
                // this.list.push('vue')

                // console.log(this.list)
                //     },0)

                console.log('created')
            },
            beforeMount() {
                console.log('beforeMount')

                console.log('beforeMount:', this.$el)
            },


            mounted() {
                console.log('mounted')
                console.log('mounted:',this.$el)

            },
            beforeUpdate() {
              
                
                console.log('beforeUpdate')
            },

            updated() {
                console.log('updated')
                
            },

            beforeDestroy() {
                console.log('beforeDestroy')
                
            },
            destroyed() {
                console.log('destroyed')
                
            },

            methods: {

                updateData() {
                    this.msg='我被改变了'
                }
            }
        });


        setTimeout(()=>{
            alert('5s后我被执行了')
            vm.$destroy()
        },5000)
    </script>
</body>

</html>